<template>
  <div>
    <div class="mui-numbox" data-numbox-min="1">
      <button class="mui-btn mui-btn-numbox-minus" type="button">-</button>
      <input class="mui-input-numbox" type="number" @change="numchange()" ref="numbox">
      <button class="mui-btn mui-btn-numbox-plus" type="button">+</button>
    </div>
  </div>
</template>
<script>
import mui from "../../mui/js/mui.min.js";
export default {
  data() {
    return {};
  },
  mounted() {
    mui(".mui-numbox").numbox(); //初始化
  },
  methods: {
    //利用@changge 监听input的变化
    numchange() {
      this.$emit("getnumboxvalue", this.$refs.numbox.value); //子组件向父组件传参
      // console.log(this.$refs.numbox.value);
    }
  },
  //接受父传值
  props: ["maxnumber"],
  //wacth监听  父向子传递的库存情况
  watch: {
    maxnumber: function(newVal, oldVal) {
      mui(".mui-numbox")
        .numbox()
        .setOption("max", newVal); //设置最大值
      // console.log(newVal);
    }
  }
};
</script>
<style scoped>
.mui-numbox {
  width: 95px;
  height: 30px;
  padding: 0 30px;
}
.mui-numbox [class*="numbox-btn"],
.mui-numbox [class*="btn-numbox"] {
  width: 30px;
  font-size: 16px;
}
</style>
